<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .sec {

            height: 400px;
            background-color: red;

        }

        .bg_blue {
            background-color: blue;
        }

        .bg_green {
            background-color: green;
        }

        .bg_yellow {
            background-color: yellow;
        }
    </style>
</head>

<body>

    <div class="sec" id='one'>

        <input type="button" id="changeToFour" value="changeToFour">

    </div>
    <div class="sec bg_blue" id='two'></div>
    <div class="sec bg_green" id='three'></div>
    <div class="sec bg_yellow" id='four'></div>

    <script>

        document.getElementById("changeToFour").addEventListener('click', function () {
            window.location.hash = "four";
        });

        window.addEventListener("hashchange", function () {


            // 获取hash值
            var hash = window.location.hash;

            console.log(hash);

            //根据获取的hash做相应的操作

        });
    </script>

</body>

</html>